#ifndef AVALON_MOCKSERVERCONNECTION_HPP
#define AVALON_MOCKSERVERCONNECTION_HPP
#include "Avalon/IO/ServerConnection.hpp"
#include "Avalon/IOTests/IOTests.hpp"

namespace Avalon {
namespace IO {
namespace Tests {

  /** \class MockServerConnection
   *  \brief An AsynchronousServerConnection used for testing purposes.
   *  \author Kamal Mansouri <kranar@hotmail.com>
   */
  class MockServerConnection : public ServerConnection {
    public:

      //! Constructs a MockServerConnection.
      MockServerConnection();

      virtual ~MockServerConnection();

      //! Rejects the next incoming Connection.
      void RejectNextConnection();

      virtual void Start();

      virtual Threading::Async<Channel*>::Ptr Accept();

      virtual bool IsConnected();

      virtual void Close();

      virtual boost::signals2::connection ConnectClosedSignal(
        const ClosedSignal::slot_type& slot);

      virtual boost::signals2::connection ConnectClosedSignal(
        const ClosedSignal::slot_type& slot, bool* isConnected);

    private:
      friend class MockClientConnection;
      boost::recursive_mutex m_mutex;
      bool m_isConnected;
      bool m_rejectNextConnection;
      std::vector<MockClientConnection*> m_pendingConnections;
      std::vector<MockClientConnection*> m_acceptedConnections;
      Threading::AsyncOwner<Channel*>::Ptr m_nextAccept;
      ClosedSignal m_closedSignal;

      bool AddPendingConnection(MockClientConnection* connection);
      void RemoveConnection(MockClientConnection* connection);
  };
}
}
}

#endif // AVALON_MOCKSERVERCONNECTION_HPP
